﻿@page
@model CnlSelectModel
@{
    Layout = "_BasicLayout";
    dynamic dict = Locale.GetDictionary("Scada.Web.Pages.CnlSelect");
    ViewBag.Title = dict.PageTitle;
    ViewBag.BodyCssClass = "modal-page";
}

@section Scripts {
    <script src="~/js/components/pager.js" asp-append-version="true"></script>
    <script src="~/js/pages/cnl-select.js" asp-append-version="true"></script>
    <script>
        var modalPostbackArgs = @Model.PostbackArgs.ToJs();
    </script>
}

<form method="post">
    <div class="mb-3">
        <label id="lblObj" for="selObj" class="form-label">@dict.lblObj</label>
        <select id="selObj" class="form-select" asp-for="ObjNum" asp-items="Model.ObjList"></select>
    </div>
    <div class="mb-3 form-check">
        <input type="checkbox" id="chkOnlySelected" class="form-check-input" asp-for="OnlySelected" />
        <label id="lblOnlySelected" class="form-check-label" for="chkOnlySelected">@dict.lblOnlySelected</label>
    </div>

    @if (Model.ChannelItems.TotalItems > 0)
    {
        <table id="tblCnl" class="table table-hover table-sm">
            <thead>
                <tr>
                    <th>@dict.SelectedColumn</th>
                    <th>@dict.NumberColumn</th>
                    <th>@dict.NameColumn</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.ChannelItems)
                {
                    <tr>
                        <td><input type="checkbox" class="form-check-input chk-sel" data-cnlnum="@item.Cnl.CnlNum" checked="@item.Selected" /></td>
                        <td>@item.Cnl.CnlNum</td>
                        <td>@item.Cnl.Name</td>
                    </tr>
                }
            </tbody>
        </table>
        <pager id="pgrCnl" asp-for="PageIndex" page-count="Model.ChannelItems.PageCount"></pager>
    }
    else if (Model.PostbackArgs == null || !Model.PostbackArgs.CloseModal)
    {
        <div class="alert alert-warning">@(Model.FilterIsEmpty ? dict.FilterRequired : dict.NoChannels)</div>
    }

    <input type="hidden" id="hidSelectedCnlNums" asp-for="SelectedCnlNums" />
    <button type="submit" class="rs-modal-submit hidden" asp-page-handler="Select">Select</button>
</form>
